$(window).load(function() {
	// console.log($(".shopping ul").children())
	// if($(".shopping ul").children().length==1){
	// 	$(".addshoppbtn").hide()
	// }
	var tmpArr=[]
	$(".cmselect>li>a").on("click", function() {

		$(this).addClass("selcetedsize").parent("li").siblings("li").find("a").removeClass(
			"selcetedsize")
	})
	console.log($(".cmselect>li>a"))
	
	
	$(".addshopp>a").eq(0).on("click", function() {
		
		// $.ajax({
		// 	url:"./../server/loaginServer.php"
		// 	
		// }).then(function(res){
		// 	
		// },function(){
		// 	
		// })
		var sizeArr=[]
		// $(".addshoppbtn").hide()
		var obj={}
		var flagsize = false
		for (var i = 0; i < $(".cmselect>li>a").length; i++) {
			if ($(".cmselect>li>a").eq(i).hasClass("selcetedsize")) {
				flagsize = true
				obj.size=$(".cmselect>li>a").eq(i).html()
				// tmpArr.push(obj)
				break;
			}
		}
		console.log(obj)
		if (flagsize) {
			console.log($(".colorul>li img").prop("src"))
			console.log($(".shopping>ul").find("li"))
			console.log(obj)
			var flag=false
			for(var i in tmpArr){
				if(tmpArr[i].size==obj.size){
					tmpArr[i].num+=Number($(".shopnum").val())
					tmpArr[i].total=tmpArr[i].price*tmpArr[i].num
					flag=true
				}
			}
			if(flag==false){
				$(".addshoppbtn").show()
				var strPrice=$(".productPrice span").eq(1).html()
				var price=strPrice.replace(",","");
				console.log(price)
				obj.color=$(".colorul span").eq(0).html()
				obj.num=Number($(".shopnum").val())
				obj.title=$(".mainRight h3").eq(0).html()
				obj.txt=$(".mainRight h2").eq(0).html()
				obj.price=Number(price)
				obj.total=obj.num*obj.price
				obj.imgstr=$(".colorul>li img").attr("src")
				var $sizeArr=$(".cmselect").find("a")
				$sizeArr.each(function(index,el){
					sizeArr.push($(el).text())
				})
				obj.sizeArr=sizeArr
				tmpArr.push(obj)
				var $li = $(
					`<li>
										<div class='smallshopimg'>
										<a href='#'><img src='${$(".colorul>li img").attr("src")}'></a>
										</div>
										<div class='shoptext'>
											<a href='#'>${$(".mainRight>h2").text()}</a>
											<a href='#' class='closebtn'>删除</a>
										</div>
									</li>`
				)
				
				$(".shopping>ul").append($li)
				$(".shopping").slideDown(500, function() {
					setTimeout(() => {
						$(".shopping").slideUp(500)
					}, 3000)
				})
			}
			CookieTools.setCookie("shoplist",JSON.stringify(tmpArr),7)
			console.log(tmpArr)
			
		}
	})
	$(".choose>span:eq(0)").on("click",function(){
		$(".shopnum").val($(".shopnum").val()-1)
		if($(".shopnum").val()<=1){
			$(".shopnum").val("1")
		}
	})
	$(".choose>span:eq(2)").on("click",function(){
		$(".shopnum").val(Number($(".shopnum").val())+1)
		
	})

$(".addshoppbtn").on("click", function() {
location.href="./shoppingcar.html"
})

})
